package net.optix.ip.commands
{
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.commands.Command;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import net.optix.ip.business.*;
	import net.optix.ip.events.DeletePractitionerEvent;
	import net.optix.ip.events.GetPractitionerEvent;
	import net.optix.ip.model.ModelLocator;
	import net.optix.ip.vo.PractitionerVO;

	public class GetPractitionerCommand implements Command, Responder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();


		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var myEvent:GetPractitionerEvent = GetPractitionerEvent( event );
			
			var delegate:UserDelegate = new UserDelegate();     
			delegate.getPractitioner( this, myEvent.practitionerID );
			
		}
		
		//----------------------------------------------------------------------------
		public function onResult( event : * = null ) : void
		{
			try
			{
				model.currentPractitioner	=	PractitionerVO.pursePractitioner(event.result);
				for(var i:int=0; i<model.practitioners.length; i++)
				{
					if(model.practitioner.practitionerID == model.practitioners[i].practitionerID)
					{
						model.practitioners[i]	=	model.currentPractitioner;
						break;
					}
					
				}
			}
			catch(error:Error)
			{
				model.result	=	"Program error!";
			}
			
			model.bSubmit	=	true;
		}
		
		//----------------------------------------------------------------------------
		public function onFault( event : * = null ) : void
		{
			trace(event.fault);
			model.result	=	"Program error";
			
		}

	}
}